package com.example.yijian.edit.view.popup;

import android.content.Context;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.SeekBar;
import android.widget.TextView;

import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.example.yijian.R;
import com.example.yijian.edit.data.FilterItem;
import com.example.yijian.edit.filter.FilterAdapter;
import com.example.yijian.utils.AssetFxUtil;
import com.example.yijian.utils.asset.NvAsset;
import com.example.yijian.utils.asset.NvAssetManager;

import java.util.ArrayList;

public class FilterPopup extends BaseCommonPopupWindow {
    private RecyclerView mFilterRecyclerList;
    private LinearLayout llFilterSeekbar;
    private SeekBar mSeekbar;
    private TextView mTvSeekbar;
    private ImageView ivFinish;

    private int mAssetType = NvAsset.ASSET_FILTER;
    private NvAssetManager mAssetManager;
    private ArrayList<FilterItem> mFilterItemArrayList;
    private FilterAdapter mFilterAdapter;

    public FilterPopup(Context context) {
        super(context);
        setContentView(R.layout.popup_filter);
        initView();
        initFilterDataList();
        initRecyclerView();
    }

    private void initView() {
        mFilterRecyclerList = findViewById(R.id.filterTypeRv);
        llFilterSeekbar = findViewById(R.id.ll_filter_seekbar);
        mSeekbar = findViewById(R.id.filter_seek);
        mTvSeekbar = findViewById(R.id.tv_filter_num);
        ivFinish = findViewById(R.id.iv_filter_finish);
        mAssetManager = getNvAssetManager();
    }

    public NvAssetManager getNvAssetManager() {
        synchronized (NvAssetManager.class) {
            if (mAssetManager == null) {
                mAssetManager = NvAssetManager.sharedInstance();
                if (mAssetManager == null) {
                    mAssetManager = NvAssetManager.init(getContext());
                }
            }
        }
        return mAssetManager;
    }


    private void initFilterDataList() {
        mFilterItemArrayList = AssetFxUtil.getFilterData(getContext(),
                getLocalData(),
                null,
                true,
                true);
    }

    private ArrayList<NvAsset> getLocalData() {
        return mAssetManager.getUsableAssets(mAssetType, NvAsset.AspectRatio_All, 0);
    }

    private void initRecyclerView() {
        mFilterAdapter = new FilterAdapter(getContext());
        mFilterAdapter.setFilterDataList(mFilterItemArrayList);
        mFilterRecyclerList.setLayoutManager(new LinearLayoutManager(getContext(), LinearLayoutManager.HORIZONTAL, false));
        mFilterRecyclerList.setAdapter(mFilterAdapter);
        mFilterAdapter.setOnItemClickListener(new FilterAdapter.OnItemClickListener() {
            @Override
            public void onItemClick(View view, int position) {

            }
        });
    }

}
